//
//  AppDelegate.m
//  CoolFM
//
//  Created by 曹曹 on 16/8/27.
//  Copyright © 2016年 曹曹. All rights reserved.
//

#import "AppDelegate.h"
#import "CFMacro.h"
#import "MainViewController.h"
//#import "PlayerViewController.h"
//#import "UIView+Frame.h"
//#import "PlayBarView.h"
//#import "PlayBarDetailView.h"
//
//#import "GXNetTool.h"
//#import "PlayerList.h"
//#import "PlayerModel.h"
//
//#import "UIImageView+WebCache.h"
//
//// model
//#import "AlbumRecord_Plays.h"
//#import "AlbumRecord.h"

@interface AppDelegate ()

// 主控制器
@property (nonatomic, strong) MainViewController *vc;
//// 播放条
//@property (nonatomic, strong) PlayBarView *playerView;
//// 播放列表
//@property (nonatomic, strong) PlayBarDetailView *playListMenu;
//// 遮挡view
//@property (nonatomic, strong) UIView *backView;
//@property (nonatomic, strong) AlbumRecord_Plays *record_plays;


@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    /**
     * window
     */
    self.window = [[UIWindow alloc] initWithFrame:SCREEN_RECT];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];
    self.vc = [[MainViewController alloc] init];
    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:_vc];
    _window.rootViewController = navigation;
    /**
     * 配置
     */
    // 状态栏的网络活动风火轮是否旋转
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    // 状态栏颜色改为白色,在plist文件中添加view controller - based Status bar appearence 并改为 NO
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    //设置所有返回按钮文字的偏移量
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -100)
                                                         forBarMetrics:UIBarMetricsDefault];
    // 设置navigationBar返回按钮的颜色为白色
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
//    /**
//     * 添加播放条
//     */
//    self.playerView = [[PlayBarView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 49, SCREEN_WIDTH, 49)];
//    [_playerView play:^(GX_Button *play) {
//        /**
//         * 播放
//         */
//        NSLog(@"click to play");
//    } pause:^(GX_Button *pause) {
//        /**
//         * 暂停
//         */
//        NSLog(@"click to pause");
//    } listOn:^(GX_Button *listOff) {
//        /**
//         * 展开
//         */
//        [self showPlayListMenu];
//        [self darkBackground];
//    } listOff:^(GX_Button *listOff) {
//        /**
//         * 收起
//         */
//        [self hidePlayListMenu];
//        [self lightBacground];
//    }];
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
//                                                                          action:@selector(gotoPlayVC:)];
//    [_playerView addGestureRecognizer:tap];
//    // 添加观察事件, 当收到消息时隐藏播放条
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(hidePlayerViewAction:)
//                                                 name:@"hidePlayerView"
//                                               object:@"playerView"];
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(showPlayerViewAction:)
//                                                 name:@"showPlayerView"
//                                               object:@"playerView"];
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(getAudioData:)
//                                                 name:@"play"
//                                               object:@"dj"];
//    [_window addSubview:_playerView];
//    [self createPlayListMenu];
    return YES;
}
//#pragma mark - 获取播放信息
//- (void)getAudioData:(NSNotification *)noti {
//    self.record_plays = noti.userInfo[@"model"];
//    self.playerView.tittleLabel.text = _record_plays.record[0].record_title;
//    [self.playerView.imageView sd_setImageWithURL:[NSURL URLWithString:_record_plays.record_play_image_url] placeholderImage:[UIImage imageNamed:@"placeholderimage"]];
//    self.playerView.detailLabel.text = [NSString stringWithFormat:@"%@ %@", _record_plays.record_play_name, _record_plays.record[0].record_file_duration];
//}
//#pragma mark - 隐藏播放条
//- (void)hidePlayerViewAction:(NSNotification *)noti {
//    self.playerView.transform = CGAffineTransformMakeScale(0, 49);
//}
//#pragma mark - 显示播放条
//- (void)showPlayerViewAction:(NSNotification *)noti {
//    self.playerView.transform = CGAffineTransformIdentity;
//}
//#pragma mark - 跳转播放界面
//- (void)gotoPlayVC:(UITapGestureRecognizer *)tap {
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"hidePlayerView"
//                                                        object:@"playerView"
//                                                      userInfo:nil];
//    PlayerViewController *playVC = [[PlayerViewController alloc] init];
//#warning 这里需要传一个model过去
//    
//    
//    playVC.record_plays = self.record_plays;
//    
//    
//    playVC.view.backgroundColor = [UIColor whiteColor];
//#warning modal VC like push animation
//    /**
//     * 模态实现push动画效果
//     */
//    CATransition *animation = [CATransition animation];
//    [animation setDuration:0.2];
//    [animation setType:kCATransitionMoveIn];
//    [animation setSubtype:kCATransitionFromTop];
//    /**
//     * 动画添加的位置，是直接加在window的layer层上，不是当前view的layer层上，如果加在view的layer层是没有那个推的效果的
//     */
//    [[[[UIApplication sharedApplication] keyWindow] layer] addAnimation:animation forKey:nil];
//    /**
//     * NO表示把系统的模态跳的动画给关闭，用我们自定义的动画来做
//     */
//    [self.vc presentViewController:playVC animated:NO completion:nil];
////    [_vc.navigationController pushViewController:playVC animated:YES];
//}
//#pragma mark - 播放列表菜单
//- (void)createPlayListMenu {
//    self.playListMenu = [[PlayBarDetailView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 251)];
//    _playListMenu.backgroundColor = [UIColor whiteColor];
//    [_window insertSubview:_playListMenu belowSubview:_playerView];
//    /*
//     * 同时创建一个大view
//     */
////    self.backView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
////    _backView.backgroundColor = [UIColor grayColor];
////    _backView.alpha = 0;
////    [_window insertSubview:_backView belowSubview:_playListMenu];
////    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToHidePlayList)];
////    [_backView addGestureRecognizer:tap];
//}
//#pragma mark - 弹出播放列表
//- (void)showPlayListMenu {
//    [UIView animateWithDuration:0.5 animations:^{
//        _playListMenu.transform = CGAffineTransformMakeTranslation(0, -300);
//    }];
//}
//#pragma mark - 隐藏播放列表
//- (void)hidePlayListMenu {
//    [UIView animateWithDuration:0.5 animations:^{
//        _playListMenu.transform = CGAffineTransformIdentity;
//    }];
//}
//- (void)darkBackground {
//    _backView.alpha = 0.5;
//}
//- (void)lightBacground {
//    _backView.alpha = 0;
//}
//#warning 这里没有改变button的状态, 有问题
//- (void)tapToHidePlayList {
//    [self lightBacground];
//    [self hidePlayListMenu];
//}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
